#!/usr/bin/env node

// class EventEmitter{
//     constructor(){
//         this.#listeners = {};
//     }
//     on(evtName,cb){
//         if(this.#listeners[evtName]){
//             this.#listeners[evtName].push(cb);
//         }else{
//             this.#listeners[evtName] = [];
//             this.#listeners[evtName].push(cb);
//         }
//     }
//     emit(evtName){
//         for(let i = 0; i<this.#listeners[evtName];i++){
//             this.#listeners[evtName][i]();
//         }
//     }

//     #listeners = null;
    
// }

class Event {
    constructor() {
      this.events = {};
    }
  
    on(eventName, callback) {
      if (!this.events[eventName]) {
        this.events[eventName] = [];
      }
      this.events[eventName].push(callback);
    }
  
    emit(eventName, ...args) {
      if (this.events[eventName]) {
        this.events[eventName].forEach(callback => callback(...args));
      }
    }
  }
  
  module.exports = Event;